var dialog = {
    error: function (messags) {
        layer.open({
            content: messags,
            icon: 2,
            title: '错误提示',
        });
    },
    success: function (messags, url) {
        layer.open({
            content: messags,
            icon: 1,
            yes: function () {
                location.href = url;
            },
        });
    },
    confirm: function (messags, url) {
        layer.open({
            content: messags,
            icon: 3,
            btn: ['是', '否'],
            yes: function () {
                location.href = url;
            },
        });
    },
    onesuccess: function (messags) {
        layer.open({
            content: messags,
            icon: 1,
            title: '成功提示',

        });
    },
    toconfirm: function (messags) {
        layer.open({
            content: messags,
            icon: 3,
            btn: ['确定'],
        });
    },

    look: function (messags) {
        //页面层-自定义

        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shadeClose: true,
            skin: 'yourclass',
            content: '自定义HTML内容'
        });
    }
}

//删除js
$('.attr-del').click(function(){
    var id = $(this).attr('attr-id');
    var message = $(this).attr('attr-message');
    var url = SCOPE.del_url;
    var $this = $(this).parents('tr');
    layer.open({
        content: "您确定要删除"+message+"吗？",
        title:'删除提示！删除信息谨慎操作！',
        icon: 3,
        btn: ['是', '否'],
        yes: function (index,layero) {
            layer.close(index);
            $.ajax({
                type:"POST",
                url:url,
                data:{id:id},
                dataType:"json",
                success:function(msg){
                    if(msg.code===1){
                        $this.remove();
                    }else{
                        dialog.error(msg.msg)
                    }
                }

            })
        }
    });

});

function accretion(data){
    data.ajaxSubmit({
        url:SCOPE.url_form,
        type:'post',
        dataType:'json',
        success : function (msg) {
            if(msg.status==1){
                dialog.success(msg)
            }else{
                dialog.error(msg)
            }
        },
        error:function(XmlHttpRequest, textStatus, errorThrown){
            alert(textStatus);
        }
    })

}
function modification(data){
    data.ajaxSubmit({
        url:SCOPE.url_edit,
        type:'post',
        dataType:'json',
        success : function (msg) {
            if(msg.status==1){
                dialog.success(msg)
            }else{
                dialog.error(msg)
            }
        },
        error:function(XmlHttpRequest, textStatus, errorThrown){
            alert(textStatus);
        }
    })
}

$('.attr-sort').change(function(){
    var id = $(this).attr('attr-id');
    var value = $(this).val();
    var $this = $(this);
    $.post(SCOPE.url_sort,{'id':id,'value':value},function(msg){
        if(msg.status==1){
            $this.val(value);
        }else{
            dialog.error(msg)
        }
    },'json')
})


//状态改变
$('.attr-status').on('click',function(){
    var data = {};
    var butt = $(this).parents('ul').prev();
    var status = $(this).attr('attr-status');
    var id= $(this).attr('attr-id');
    var m = $(this).html();
    // var n =butt.attr('class').match(/btn-status-([0-9]{1})/)[1];
    var url = SCOPE.url_status;
    $.get(url,{'status':status,'id':id},function(msg){
        if(1==msg.status){
            if(status==1){
                butt.removeClass('label-warning');
                butt.addClass('label-info');
                butt.html(m+'<span class="caret"></span>');
            }else{
                butt.removeClass('label-info');
                butt.addClass('label-warning');
                butt.html(m+'<span class="caret"></span>');
            }
        }else{
            dialog.error(msg.message);
        }
    },'json');
})



